package com.ruoyi.xzs.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.xzs.domain.KnowsQuestion;
import com.ruoyi.xzs.service.IKnowsQuestionService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 知识点题目关联Controller
 * 
 * @author li
 * @date 2023-03-14
 */
@RestController
@RequestMapping("/knowsQuestion")
public class KnowsQuestionController extends BaseController
{
    @Autowired
    private IKnowsQuestionService knowsQuestionService;

    /**
     * 查询知识点题目关联列表
     */
    @RequiresPermissions("xzs:knowsQuestion:list")
    @GetMapping("/list")
    public TableDataInfo list(KnowsQuestion knowsQuestion)
    {
        startPage();
        List<KnowsQuestion> list = knowsQuestionService.selectKnowsQuestionList(knowsQuestion);
        return getDataTable(list);
    }

    /**
     * 导出知识点题目关联列表
     */
    @RequiresPermissions("xzs:knowsQuestion:export")
    @Log(title = "知识点题目关联", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KnowsQuestion knowsQuestion)
    {
        List<KnowsQuestion> list = knowsQuestionService.selectKnowsQuestionList(knowsQuestion);
        ExcelUtil<KnowsQuestion> util = new ExcelUtil<KnowsQuestion>(KnowsQuestion.class);
        util.exportExcel(response, list, "知识点题目关联数据");
    }

    /**
     * 获取知识点题目关联详细信息
     */
    @RequiresPermissions("xzs:knowsQuestion:query")
    @GetMapping(value = "/{kId}")
    public AjaxResult getInfo(@PathVariable("kId") Long kId)
    {
        return success(knowsQuestionService.selectKnowsQuestionByKId(kId));
    }

    /**
     * 新增知识点题目关联
     */
    @RequiresPermissions("xzs:knowsQuestion:add")
    @Log(title = "知识点题目关联", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KnowsQuestion knowsQuestion)
    {
        return toAjax(knowsQuestionService.insertKnowsQuestion(knowsQuestion));
    }

    /**
     * 修改知识点题目关联
     */
    @RequiresPermissions("xzs:knowsQuestion:edit")
    @Log(title = "知识点题目关联", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KnowsQuestion knowsQuestion)
    {
        return toAjax(knowsQuestionService.updateKnowsQuestion(knowsQuestion));
    }

    /**
     * 删除知识点题目关联
     */
    @RequiresPermissions("xzs:knowsQuestion:remove")
    @Log(title = "知识点题目关联", businessType = BusinessType.DELETE)
	@DeleteMapping("/{kIds}")
    public AjaxResult remove(@PathVariable Long[] kIds)
    {
        return toAjax(knowsQuestionService.deleteKnowsQuestionByKIds(kIds));
    }
}
